package com.weixing.mall.provider.controller;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.AgentAuth;
import com.weixing.mall.core.support.auth.AuthUtil;
import com.weixing.mall.provider.api.model.vo.UserInfoVo;
import com.weixing.mall.provider.model.domain.Agent;
import com.weixing.mall.provider.api.model.enums.AgentRoleEnum;
import com.weixing.mall.provider.service.IAgentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 代理商登录相关接口
 *
 * @author siashan
 * @since v2.0
 */
@RestController
@RequestMapping("")
@Validated
@Api(value = "前端:代理商", tags = "前端:代理商登录相关")
public class PassportController extends BaseController {
    @Autowired
    private IAgentService agentService;

    @GetMapping("userInfo")
    public Result<UserInfoVo> info(){
        AgentAuth agentAuth = AuthUtil.getAgentExt();
        Long agentId = agentAuth.getAid();
        Agent agent = agentService.getById(agentId);
        UserInfoVo infoVo = new UserInfoVo();
        infoVo.setUserName(agent.getAgentName());
        AgentRoleEnum agentRoleEnum = AgentRoleEnum.getRole(agent.getAgentLevel(), agent.getAgentType());

        return ResultUtil.success(infoVo);
    }
}
